package com.example.todolist.controller;

import com.example.todolist.entity.ReviewTask;
import com.example.todolist.entity.Summary;
import com.example.todolist.entity.Task;
import com.example.todolist.entity.TaskEachDay;
import com.example.todolist.mapper.ReportMapper;
import com.example.todolist.mapper.ReviewTaskMapper;
import com.example.todolist.mapper.TaskEachDayMapper;
import com.example.todolist.mapper.TaskMapper;
import com.example.todolist.service.SummaryService;
import com.example.todolist.service.TaskEachDayService;
import com.example.todolist.service.TaskService;
import com.example.todolist.tools.ResponseBody;
import com.example.todolist.tools.StringToDateConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/summary")
public class SummaryController {
    @Autowired
    private SummaryService summaryService;
    @Autowired
    private ReportMapper reportMapper;
    @Autowired
    private TaskMapper taskMapper;
    @Autowired
    private TaskService taskService;
    @Autowired
    private ReviewTaskMapper reviewTaskMapper;
    @Autowired
    private TaskEachDayMapper taskEachDayMapper;
    public StringToDateConverter stringToDateConverter = new StringToDateConverter();
    @GetMapping("/getThisMonthTask")
    public ResponseBody<List<Task>> getThisMonthTask(@RequestParam Integer userId,@RequestParam Integer year,@RequestParam Integer month) {
        return summaryService.getThisMonthTask(userId,year,month);
    }
    @GetMapping("/getAllTask")
    public ResponseBody<List<Task>> getAllTask(@RequestParam Integer userId)
    {
        return new ResponseBody<>(200,"success",taskMapper.getALLTask(userId));
    }
    @GetMapping("/getThisMonthReviewTask")
    public ResponseBody<List<ReviewTask>> getThisMonthReviewTask(@RequestParam Integer userId,@RequestParam Integer year,@RequestParam Integer month) {
        return summaryService.getThisMonthReviewTask(userId,year,month);
    }
    @GetMapping("/getAllReviewTask")
    public ResponseBody<List<ReviewTask>> getAllReviewTask(@RequestParam Integer userId)
    {
        return new ResponseBody<>(200,"success",reviewTaskMapper.getAllReviewTask(userId));
    }
    @GetMapping("/getSummary")
    public ResponseBody<Summary> getSummary(@RequestParam Integer userId) {
        return summaryService.getSummary(userId);
    }
    @GetMapping("/getOneDayTask")
    public ResponseBody<List<Task>> getOneDayTask(@RequestParam Integer userId,@RequestParam String date) {
        return summaryService.getOneDayTask(userId,stringToDateConverter.StringToDate(date));
    }

    @GetMapping("/getOneDayReviewTask")
    public ResponseBody<List<ReviewTask>> getOneDayReviewTask(@RequestParam Integer userId, @RequestParam String date) {
        return summaryService.getOneDayReviewTask(userId,stringToDateConverter.StringToDate(date));
    }

    @GetMapping("/getForgetReviewTask")
    public ResponseBody<List<ReviewTask>> getForgetReviewTask(@RequestParam Integer userId){
        return summaryService.getForgetReviewTask(userId);
    }

    @GetMapping("/getInformationToGPT")
    public ResponseBody<List<String>> getInformationToGPT(@RequestParam Integer userId)
    {
        return summaryService.getInformationToGPT(userId);
    }

    @PostMapping("/recordWeekReport")
    public ResponseBody<Integer> recordWeekReport(@RequestParam Integer userId,@RequestParam String content)
    {
        if(reportMapper.countTheUserReport(userId)==0)
        {
            reportMapper.insertWeekReport(userId,content);
            return new ResponseBody<>(200,"success",1);
        }
        reportMapper.recordWeekReport(userId,content);
        return new ResponseBody<>(200,"success",1);
    }

    @GetMapping("/getWeekReport")
    public ResponseBody<String> getWeekReport(@RequestParam Integer userId)
    {
        return new ResponseBody<>(200,"success",reportMapper.getWeekReport(userId));
    }

    @GetMapping("/getTaskEachDay")
    public ResponseBody<TaskEachDay> getTaskEachDay(@RequestParam Integer userId)
    {
        return new ResponseBody<>(200,"success",taskEachDayMapper.getTaskEachDay(userId));
    }

    @GetMapping("/getTypeTask")
    public ResponseBody<List<Task>> getTypeTask(@RequestParam Integer userId,@RequestParam String taskType)
    {
        return new ResponseBody<>(200,"success",taskService.getTypeTask(userId,taskType));
    }
}
